Fix deadlock caused by mx.clear_streams() holding GIL - #4413
Merged
Conversation
…IL while synchronously waiting for Metal
zcbenz
marked this pull request as ready for review
August 27, 2026 03:16
zcbenz
approved these changes
Aug 27, 2026
| # in Python would never run. | ||
| def test_synchronize_releases_gil(self): | ||
| a = self._adopted_source(1024) | ||
| faulthandler.dump_traceback_later(120, exit=True) |
Member
There was a problem hiding this comment.
I think we can use a much shorter timeout here.
Contributor
Author
There was a problem hiding this comment.
I will update once arrived to the office
Contributor
Author
There was a problem hiding this comment.
Picked 30 seconds. The submitted work (a handful of 1024×1024 matmuls) finishes in well under a second on any hardware, so 30 seconds still leaves generous headroom on heavily loaded CI runners. Let me know if it is fine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fix the deadlock experienced in the tests. See #4410 for more information.
Added a regression test which proves it, and added even an additional fix in another point it could have backfired as well.
Notes
macOS CI sets
METAL_DEVICE_WRAPPER_TYPE: 1which changes the timing and contributes to the fact works on my machine but not on CI...